from rj_casmart import RJ_api
from utils import (
    save_dict_to_json,
    del_old_content,
    add_ad_service,
    header_placeholder,
    footer_placeholder,
)

# from rj_casmart.rjmart.parameModel import rjUpdateProductModel

import time


def main():
    rj = RJ_api()

    brandIds = [65]
    try:
        for product in rj.official_getProductList(brandIds):

            product_detail = rj.official_getProductDetailList(
                [item["id"] for item in product]
            )
            time.sleep(1)

            rj.official_updateProductList(
                [
                    {
                        "productNum": item["productNum"],
                        "photos": item["photos"],
                        "desc": add_ad_service()
                        + header_placeholder()
                        + del_old_content(item["desc"])
                        + footer_placeholder(),
                    }
                    for item in product_detail
                ]
            )
            time.sleep(1)
    except Exception as e:
        print(e)


if __name__ == "__main__":
    main()
